<template>
  <div>
    <van-nav-bar
      :title="comment.reply_count>0 ?`${comment.reply_count}条评论` : '暂无评论'"
    />
    <van-icon name="cross" slot="left" @click="$emit('close')"></van-icon>
    <comment-item :comment="comment"></comment-item>
    <comment-list :source="comment.com_id" type='c'></comment-list>
     <div class="scroll-wrap">
         <comment-item :comment="comment"></comment-item>
         <van-cell title="所有回复"></van-cell>
         <comment-list :source="comment.com_id" type="c" :list="commentList"></comment-list>
         <div class="reply-bottom">
             <van-button class="write-btn" type="default" round size="small"  @click="isPostShow = true">回复评论</van-button>
         </div>
          <van-popup v-model="isPostShow" position="bottom">
      <!-- 新增弹层 -->
      <CommentPost :target="comment.com_id"
      @onPostSuccess="onPostSuccess"></CommentPost>
    </van-popup>
     </div>
  </div>
</template>

<script>
import CommentItem from '../comment-item.vue'
import CommentList from '../../comment-list.vue/index.vue'
import CommentPost from './comment-post.vue'
export default {
  name: 'CommentReply',
  components: { CommentItem, CommentList, CommentPost },
  props: {
    comment: Object
  },
  data () {
    return {
      commentList: [], // 发表评论
      isPostShow: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onPostSuccess (comment) {
      // 关闭弹层
      this.isPostShow = false
      //   添加评论数量
      this.totalCount++
      //   添加评论到列表
      // this.$refs.commentRef.list.unshift(comment)
      this.commentList.unshift(comment)
    }
  }
}
</script>

<style lang="less">
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
</style>